#ifndef _UTIL_H
#define _UTIL_H

#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <cassert>

using namespace std;

#define ENTITY_ONLY 0
#define RELATION_ONLY 1
#define JOINT 2

std::string decap(std::string s);

double power(double a, int n);

int mapInsert(const string &s);

string gFeature(const string &s);

template <typename T> 
void writeVector(ostream &out, const vector <T> &v, const string &c=" ") {
   for (int i=0; i<v.size(); ++i) out<<v[i]<<c;
   out<<"\n";
}

// returns the index of the place in the array where the element is found
// asserts that element is indeedd there
template <typename T> 
int findWhere(const vector <T> &v, const T &e) {
    for (int i=0; i < v.size(); ++i) {
      if (v[i]==e) return i;
   }
   assert(false);
}

// used to convert an int or a double to string
template <typename T>
string itos(T n) {  
   std::ostringstream ost;
   ost<<n;
   return ost.str();
}

// removes duplicates from the vector
template <typename T>
void remove_duplicates(vector <T> &a) {
   int i=1;
   while (i < a.size()) {
      bool rem=false;
      for (int j=0; j<i; ++j) {
         if (a[i]==a[j]) {
            rem = true;
            break;
         }
      }
      if (rem) {
         a.erase(a.begin()+i);
      }
      else ++i;
   }
}



#endif
